package com.lianniu.web.tea.base.service.impl;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.lianniu.web.base.BaseResult;
import com.lianniu.web.tea.base.dao.TeaBaseDao;
import com.lianniu.web.tea.base.service.TeaBaseService;
import com.lianniu.web.tea.token.dao.TeaAccessTokenDao;
import com.lianniu.web.util.TeaContant;
import com.lianniu.web.util.WeiXinDownloadUtil;

@Service
@Transactional
public class TeaBaseServiceImpl implements TeaBaseService {

	private final static Logger logger = Logger.getLogger(TeaBaseServiceImpl.class);

	
	@Resource
	private TeaBaseDao teaBaseDao;
	
	@Autowired
	private TeaAccessTokenDao teaAccessTokenDao;

	/**
	 * 查询林业机构
	 */
	public BaseResult getForestryList(String areaCode) {
		logger.info("TeaProductServiceImpl getTeaProductList start");
		List<Map> forestryList = teaBaseDao.getForestryList(areaCode);
		logger.info("TeaProductServiceImpl getTeaProductList end");
		return BaseResult.success(forestryList);
	}

	/**
	 * 通过mediaId在微信服务器下载图片
	 */
	public BaseResult uploadImage(String mediaId,String component) {
		String accessToken = teaAccessTokenDao.getAccessTocken().getAccessTocken();
		String pic = WeiXinDownloadUtil.downloadMedia(mediaId, accessToken,component+"/");
		return BaseResult.success(pic);
	}
	
	
}
